<template>
    <div class="userDownload">
        <div class="logo" :style="{
            'background-image': 'url(' + require('@/assets/img/login/' + $config.logoBgUrl) + ')',
            'margin-left': $config.logoBg_left,
        }"></div>

        <div class="language_dropdown">
            <switchLang></switchLang>
       
           
        </div>

        <div class="userDownload_content">
            <div class="content1" v-show="isAjax && isHave">
           
                <h3>{{ currData.label }}</h3>
                <p class="subTitle">{{ backData.fileName }}</p>
                <p>
                    <span>{{ $t('userDownload.userDownload1') }}: </span>
                    <span>{{ $t(currData.softwareName) }}</span>
                </p>
                <p>
                    <span>{{ $t('userDownload.userDownload2') }}: </span>
                    <span>{{ $t(currData.applicableProducts) }}</span>
                </p>
                <p>
                    <span>{{ $t('userDownload.userDownload3') }}: </span>
                    <span>{{ $t(currData.operatingSystem) }}</span>
                </p>
                <p>
                    <span>{{ $t('userDownload.userDownload4') }}: </span>
                    <span>{{ backData.fileSize }}</span>
                </p>
                <p>
                    <span>{{ $t('userDownload.userDownload5') }}: </span>
                    <span>{{ backData.updateTime }}</span>
                </p>
                <el-button type="primary" icon="el-icon-download" @click="toDownload">{{
                    $t('userDownload.userDownload6') }}</el-button>
            </div>

            <div class="content2" v-show="isAjax && !isHave">
         
                <p>{{ $t('userDownload.userDownload7') }}</p>
            </div>
        </div>

    </div>
</template>

<script>
import switchLang from '@/components/lang/index';  // 全局切换语言组件
import { downloadFile } from '@/utils/index';
import { messages } from '@/i18n';
import langs from '@/i18n/langs';
import SparkMD5 from 'spark-md5';
export default {
    // 上传设计
    name: 'userDownload',

    data() {
        return {
           
            language: '',
            // 加密部分 platformType=oem&cientType=3&versionType=3000
            downloadData: [
                {
                    label: "DentalScanner3.0",
                    type: 'original',
                    value: '9',
                    softwareName: 'userDownload.DentalScanner3_0_1',
                    applicableProducts: 'userDownload.DentalScanner3_0_2',
                    operatingSystem: 'userDownload.DentalScanner3_0_3',
                    versionFormat: '0000',
                    md5: '68fcce9f96b5bc54956358ce334b7f78',
                },
                {
                    label: "DentalScanner3.0",
                    type: 'original',
                    value: '9',
                    softwareName: 'userDownload.DentalScanner3_0_1',
                    applicableProducts: 'userDownload.DentalScanner3_0_2',
                    operatingSystem: 'userDownload.DentalScanner3_0_3',
                    versionFormat: '1000',
                    md5: '43d2eeb69c513119f20a0902fc4f9475',
                },
                {
                    label: "DentalScanner3.0",
                    type: 'original',
                    value: '9',
                    softwareName: 'userDownload.DentalScanner3_0_1',
                    applicableProducts: 'userDownload.DentalScanner3_0_2',
                    operatingSystem: 'userDownload.DentalScanner3_0_3',
                    versionFormat: '1000(15)',
                    md5: '5cacd5862ed0f37fded2ca6d1cf74081',
                },

                {
                    label: "DentalScanner2.0",
                    type: 'original',
                    value: '8',
                    softwareName: 'userDownload.DentalScanner2_0_1',
                    applicableProducts: 'userDownload.DentalScanner2_0_2',
                    operatingSystem: 'userDownload.DentalScanner2_0_3',
                    versionFormat: '0000',
                    md5: 'b7e7a6615e5fc03532a9a87d216f14a8',
                },

                {
                    label: "DentalScanner2.0",
                    type: 'original',
                    value: '8',
                    softwareName: 'userDownload.DentalScanner2_0_1',
                    applicableProducts: 'userDownload.DentalScanner2_0_2',
                    operatingSystem: 'userDownload.DentalScanner2_0_3',
                    versionFormat: '1000',
                    md5: '0e0165e3e6dbfedbf8f5ae2bd4c38986',
                },

                {
                    label: "DentalScanner2.0",
                    type: 'original',
                    value: '8',
                    softwareName: 'userDownload.DentalScanner2_0_1',
                    applicableProducts: 'userDownload.DentalScanner2_0_2',
                    operatingSystem: 'userDownload.DentalScanner2_0_3',
                    versionFormat: '1000(15)',
                    md5: '89ced572c25500e1876e36dc118d9afa',
                },

                {
                    label: "DentalScanner2.0",
                    type: 'oem',
                    value: '8',
                    softwareName: 'userDownload.DentalScanner2_0_1',
                    applicableProducts: 'userDownload.DentalScanner2_0_2',
                    operatingSystem: 'userDownload.DentalScanner2_0_3',
                    versionFormat: '1100',
                    md5: '99c7962b325f0f0f819e3122935c9f71',
                },

                {
                    label: "DentalScanner2.0",
                    type: 'oem',
                    value: '8',
                    softwareName: 'userDownload.DentalScanner2_0_1',
                    applicableProducts: 'userDownload.DentalScanner2_0_2',
                    operatingSystem: 'userDownload.DentalScanner2_0_3',
                    versionFormat: '2100',
                    md5: 'b2367c6131f3c635edb528a5875e9996',
                },

                {
                    label: "DentalScanner2.0",
                    type: 'oem',
                    value: '8',
                    softwareName: 'userDownload.DentalScanner2_0_1',
                    applicableProducts: 'userDownload.DentalScanner2_0_2',
                    operatingSystem: 'userDownload.DentalScanner2_0_3',
                    versionFormat: '2110',
                    md5: '5a6d4f203ef7970029d7589729e76f46'
                },

                {
                    label: "DentalScanner2.0",
                    type: 'oem',
                    value: '8',
                    softwareName: 'userDownload.DentalScanner2_0_1',
                    applicableProducts: 'userDownload.DentalScanner2_0_2',
                    operatingSystem: 'userDownload.DentalScanner2_0_3',
                    versionFormat: '3110',
                    md5: '31e030064425bed79eb335fdb8e8f37b'
                },

                {
                    label: "IntraoralScanner",
                    type: 'original',
                    value: '2',
                    softwareName: 'userDownload.IntraoralScanner_1',
                    applicableProducts: 'userDownload.IntraoralScanner_2',
                    operatingSystem: 'userDownload.IntraoralScanner_3',
                    versionFormat: '0000',
                    md5: 'fbc608e828cef113ea037754d3d544be',
                },

                {
                    label: "IntraoralScanner",
                    type: 'original',
                    value: '2',
                    softwareName: 'userDownload.IntraoralScanner_1',
                    applicableProducts: 'userDownload.IntraoralScanner_2',
                    operatingSystem: 'userDownload.IntraoralScanner_3',
                    versionFormat: '1000',
                    md5: 'bc56608bc9df5d8617656a25ae217e62',
                },

                {
                    label: "IntraoralScanner",
                    type: 'original',
                    value: '2',
                    softwareName: 'userDownload.IntraoralScanner_1',
                    applicableProducts: 'userDownload.IntraoralScanner_2',
                    operatingSystem: 'userDownload.IntraoralScanner_3',
                    versionFormat: '1000(15)',
                    md5: '0c23934ae1eff880867c8ff96891171a',
                },
                {
                    label: "IntraoralScanner",
                    type: 'original',
                    value: '2',
                    softwareName: 'userDownload.IntraoralScanner_1',
                    applicableProducts: 'userDownload.IntraoralScanner_2',
                    operatingSystem: 'userDownload.IntraoralScanner_3',
                    versionFormat: '0001',
                    md5: '699a06583e61b4e2607d8d9448a35ebd',
                },
                {
                    label: "IntraoralScanner",
                    type: 'original',
                    value: '2',
                    softwareName: 'userDownload.IntraoralScanner_1',
                    applicableProducts: 'userDownload.IntraoralScanner_2',
                    operatingSystem: 'userDownload.IntraoralScanner_3',
                    versionFormat: '1001',
                    md5: 'dcfb603ad90fce01f92f15d2d8dd1506',
                },


                {
                    label: "IntraoralScanner",
                    type: 'oem',
                    value: '2',
                    softwareName: 'userDownload.IntraoralScanner_1',
                    applicableProducts: 'userDownload.IntraoralScanner_2',
                    operatingSystem: 'userDownload.IntraoralScanner_3',
                    versionFormat: '2000',
                    md5: '05cc4f4cfb541d198e09dfc54ed2b43f',
                },
                {
                    label: "IntraoralScanner",
                    type: 'oem',
                    value: '2',
                    softwareName: 'userDownload.IntraoralScanner_1',
                    applicableProducts: 'userDownload.IntraoralScanner_2',
                    operatingSystem: 'userDownload.IntraoralScanner_3',
                    versionFormat: '2001',
                    md5: 'd538871d074dfb37bdda31c80f8d7051',
                },

                {
                    label: "IntraoralScanner",
                    type: 'oem',
                    value: '2',
                    softwareName: 'userDownload.IntraoralScanner_1',
                    applicableProducts: 'userDownload.IntraoralScanner_2',
                    operatingSystem: 'userDownload.IntraoralScanner_3',
                    versionFormat: '3000',
                    md5: '5780e463ed18fa2b12abd569a7fa747f',
                },


                {
                    label: "IntraoralScanner",
                    type: 'oem',
                    value: '2',
                    softwareName: 'userDownload.IntraoralScanner_1',
                    applicableProducts: 'userDownload.IntraoralScanner_2',
                    operatingSystem: 'userDownload.IntraoralScanner_3',
                    versionFormat: '3200',
                    md5: 'd2dca13575cd91a75681bb7017b8e1d7',
                },

                {
                    label: "IntraoralScanner",
                    type: 'oem',
                    value: '2',
                    softwareName: 'userDownload.IntraoralScanner_1',
                    applicableProducts: 'userDownload.IntraoralScanner_2',
                    operatingSystem: 'userDownload.IntraoralScanner_3',
                    versionFormat: '3300',
                    md5: '253a3382e46ba63420a281d66f47709e',
                },

                {
                    label: "OrthoSimulator",
                    type: 'original',
                    value: '4',
                    softwareName: 'userDownload.OrthoSimulator_1',
                    applicableProducts: 'userDownload.OrthoSimulator_2',
                    operatingSystem: 'userDownload.OrthoSimulator_3',
                    versionFormat: '0000',
                    md5: 'a49ddef662ec01e091527a63a98cdc24'

                },

                {
                    label: "OrthoSimulator",
                    type: 'original',
                    value: '4',
                    softwareName: 'userDownload.OrthoSimulator_1',
                    applicableProducts: 'userDownload.OrthoSimulator_2',
                    operatingSystem: 'userDownload.OrthoSimulator_3',
                    versionFormat: '1000',
                    md5: 'aacf36947f36d5fcefe6e17a87ec10a4'
                },

                {
                    label: "OrthoSimulator",
                    type: 'oem',
                    value: '3',
                    softwareName: 'userDownload.OrthoSimulator_1',
                    applicableProducts: 'userDownload.OrthoSimulator_2',
                    operatingSystem: 'userDownload.OrthoSimulator_3',
                    versionFormat: '3000',
                    md5: 'a05fe29e568a857b74e7dc4090a7c421'
                },

                {
                    label: "Splintdesign",
                    type: 'original',
                    value: '6',
                    softwareName: 'userDownload.Splintdesign_1',
                    applicableProducts: 'userDownload.Splintdesign_2',
                    operatingSystem: 'userDownload.Splintdesign_3',
                    versionFormat: '0000',
                    md5: '6d70ab3f739069287fe60d32de755fe0',

                },

                {
                    label: "Splintdesign",
                    type: 'original',
                    value: '6',
                    softwareName: 'userDownload.Splintdesign_1',
                    applicableProducts: 'userDownload.Splintdesign_2',
                    operatingSystem: 'userDownload.Splintdesign_3',
                    versionFormat: '1000',
                    md5: '1690aa3ee7da0b4c55913243e09c85f2',
                },

                {
                    label: "Splintdesign",
                    type: 'oem',
                    value: '6',
                    softwareName: 'userDownload.Splintdesign_1',
                    applicableProducts: 'userDownload.Splintdesign_2',
                    operatingSystem: 'userDownload.Splintdesign_3',
                    versionFormat: '3000',
                    md5: '53a32152cd4774f28cc7cf8bddba7ffb',
                },

                {
                    label: "Crowndesign",
                    type: 'original',
                    value: '7',
                    softwareName: 'userDownload.Crowndesign_1',
                    applicableProducts: 'userDownload.Crowndesign_2',
                    operatingSystem: 'userDownload.Crowndesign_3',
                    versionFormat: '0000',
                    md5: 'b9945ab4f40ca7460133627f3ceb92aa',
                },
                {
                    label: "Crowndesign",
                    type: 'original',
                    value: '7',
                    softwareName: 'userDownload.Crowndesign_1',
                    applicableProducts: 'userDownload.Crowndesign_2',
                    operatingSystem: 'userDownload.Crowndesign_3',
                    versionFormat: '1000',
                    md5: '72dcd3feef89c7cf835b09629581589d',
                },

                {
                    label: "Crowndesign",
                    type: 'oem',
                    value: '7',
                    softwareName: 'userDownload.Crowndesign_1',
                    applicableProducts: 'userDownload.Crowndesign_2',
                    operatingSystem: 'userDownload.Crowndesign_3',
                    versionFormat: '3000',
                    md5: 'ea6ac3a7b1ea2cb56de9c71e6c09a178',

                },
            ],
           
            platformType: '',
            currData: {},
            // 后返回的数据
            backData: {},
            
            // 确定是走了接口请求之后的
            isAjax: false,
            // 确定是否有正常的下载数据
            isHave: false,
        };
    },
    components: {
        switchLang
    },
    mounted() { },
    created() {

        // 获取路由上传递过来的
        this.getRouterParameter();

        // 初始化国际化
        this.initLanguage();

    },
    methods: {
        initLanguage() {
            let language = navigator.language || navigator.userLanguage;

            if (language === 'zh-CN') {
                this.language = 'cn';
            } else {
                this.language = 'en';
            }
            let storageLang = localStorage.getItem('downloadLang');
            if(storageLang){
                this.language = storageLang;
            }
            this.languageHandle(this.language);
        },
        getRouterParameter() {

            console.log('router---', this.$route.fullPath);

            let md5 = this.$route.fullPath.split("?")[1];
            let needArr = this.downloadData.filter(f => f.md5 === md5);
            if (needArr && needArr.length > 0) {
                this.currData = needArr[0];
            }
            this.toQueryData();
        },

        toQueryData() {



            this.$http
                .get(
                    `/clientinstallationpackage/userDisplayInterface?clientType=${this.currData.value}&versionType=${this.currData.versionFormat}`,
                )
                .then(({ data: res }) => {
                    this.isAjax = true;
                    if (res.code !== 0) {
                        return this.$message.error(res.msg);
                    } else {
                        // this.form.code = res.data
                        if (res.data) {
                            if (res.data.isShow === '1') {
                                this.isHave = true;

                                this.backData = res.data;
                            } else {
                                this.isHave = false;
                            }


                        } else {
                            this.isHave = false;
                        }
                    }
                })
                .catch((err) => {
                    console.log('err', err);
                });
        },
      
       

        languageHandle(type) {
            this.language = type;
            this.$i18n.locale = type;
            localStorage.setItem('downloadLang', type);
            let baseTitle = messages[type]['brand'][this.$config.labelText];
            let prefixTitle = langs[this.language]['userDownload']['userDownload8'];
            document.title = prefixTitle + '-' + baseTitle;


        },

        toDownload() {
            downloadFile(this.backData.url,this.backData.fileName);
            let formData = {
                clientType: this.backData.clientType,
                version: this.backData.version,
            };
            this.$http
                .post('/clientsoftwaredownloadlog/save', formData)
                .then((res) => {
                    if (res.data.code !== 0) {
                        return this.$message.error(res.data.msg);
                    }
                })
                .catch((e) => {
                    this.uploadDialog.saveLoading = false;
                    console.error(e);
                });
        },



    },
};
</script>

<style lang="scss">
.userDownload {
    width: 100%;
    height: 100%;
    position: relative;

    .userDownload_content {
        position: absolute;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);

        .content1 {
            text-align: left;
            position: relative;

            >h3 {
                font-size: 40px;
                margin-bottom: 20px;
            }

            p {
                font-size: 23px;
                margin-bottom: 20px;
            }

            .subTitle {
                font-size: 20px;
                font-weight: 700;
            }

            .el-button {
                position: absolute;
                left: 50%;
                transform: translate(-50%, 0);
                padding: 16px 18px;
                font-size: 25px;
            }
        }

        .content2 {
            font-size: 20px;
            font-weight: 600;
        }
    }
}
</style>